package job.qi.dftf;

import java.util.HashMap;
import java.util.Map;

public class Qi_DFTF_Record {

    private Map<FieldCounter, Long> map = new HashMap<FieldCounter, Long>();

    public Qi_DFTF_Record() {
        for (FieldCounter fc : FieldCounter.values()) {
            map.put(fc, 0L);
        }
    }

    public Qi_DFTF_Record(String s) {
        this();

        String[] t = s.split("\t");
        for (int i = 0; i < FieldCounter.values().length; ++i) {
            map.put(FieldCounter.values()[i], Long.valueOf(t[i]));
        }
    }

    public long get(FieldCounter key) {
        return map.get(key);
    }

    public Qi_DFTF_Record set(FieldCounter key, long value) {
        map.put(key, value);
        return this;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        for (FieldCounter fc : FieldCounter.values()) {
            sb.append("\t");
            sb.append(map.get(fc));
        }
        return sb.toString().trim();
    }

    public void add(Qi_DFTF_Record record) {
        for (FieldCounter fc : FieldCounter.values()) {
            this.set(fc, this.get(fc) + record.get(fc));
        }
    }

    public static enum FieldCounter {

        anchor_tf, title_tf, body_tf, query_tf, url_tf,

        anchor_df, title_df, body_df, query_df, url_df,

        all_tf, all_df;

    }

}
